CodeCraft
  • Github
  • Instagram
< >

Age In Days

TIME LIMIT = 5 SECS.

  • Read an integer value corresponding to a person's age (in days) and print it in years, months and days, followed by its respective message
    “ano(s)”, “mes(es)”, “dia(s)”. Note: only to facilitate the calculation, consider the whole year with 365 days and 30 days every month.
    In the cases of test there will never be a situation that allows 12 months and some days, like 360, 363 or 364. This is just an exercise for
    the purpose of testing simple mathematical reasoning.
Input Output
The input file contains 1 integer value. Print the output, like the following example

Example Test Case
Input Output
800 2 ano(s)
2 mes(es)
10 dia(s)
Solution

#include <stdio.h> int main() { int n; // n' is the variable used to store the number of days scanf("%d", & n); //Accept 'n' /* Anos = Years, so days divided by 365 will be equal to the number of years in question. Meses= Months, so the remainder of the number of days divided by 365, in turn divided by 30 will be equal to the number of months in question. Dias = Days, so the number subtracted by number of years*365 and months*30 (because 1 year = 365 days and 1 month = 30 days [in question]) will be equal to the number of days in question. */ int anos = n / 365; //Anos = Years int meses = (n % 365) / 30; //Meses = Months int dias = n - (anos * 365) - (meses * 30); //Dias = Days //Print the output in 'Anos', 'Meses', and 'Dias' printf("%d ano(s)\n%d mes(es)\n%d dia(s)", anos, meses, dias); return 0; }
  • #1 Squared and cubic
  • #2 Digits
  • #3 Multiple Adder
  • #4 Grains in a Chessboard
  • #5 Age In Days
  • #6 Stay or Go
  • #7 Cipher

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();